package com.ruoyi.business.dao;

import com.ruoyi.business.domain.DispatchList;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.Transient;


/**
 * DispatchListDao接口
 *
 * @author liutietou
 * @since 1.0 2025-07-19
 */
@Repository
public interface DispatchListDao extends JpaRepository<DispatchList, Integer>, JpaSpecificationExecutor<DispatchList> {

@Query(value ="SELECT  ifatherid   FROM  ufsystem..UA_Identity  WHERE  cacc_id=:accountid  AND   cvouchtype='dispatch'  ",nativeQuery = true)
    int  getDispatchId(@Param("accountid") String  accountid);


@Modifying
@Query(value = "UPDATE  ufsystem..UA_Identity  SET  ifatherid=ifatherid+1   WHERE  cacc_id=:accountid  AND   cvouchtype='dispatch'",nativeQuery = true)
    int  updateDispatchId(@Param("accountid")String  accountid);

    @Query(value = "SELECT max(cdlcode)  FROM   DispatchList  WHERE   len(cdlcode)=12  and  cdlcode  LIKE  :yearmonth ",nativeQuery = true)
    String  getCdlcode(@Param("yearmonth") String  yearmonth);

}
